********************************************************************************
* Figure 4: RD specifications - effect of earlier eligibility on political attitudes
********************************************************************************

* t_0
foreach var in  index  party_closer1 interest_polit vote_agree vote_party  member_party  {
	
	use "Data_temp/polit_involv.dta", clear
	
	foreach cov in female born_abroad mwork14 mum_lowedu white_brit  employed low_edu married ///
		 england  scotland wales north_ireland birth_month {
			qui recode `cov' (.=99)
			qui tab `cov' if `var'<. & inrange(age0,-24,24) & rel_year>=0 & age0!=0, gen(contr_`cov')
			drop contr_`cov'1
			}
	
	
		cap drop dummy*
		qui tab year if `var'<. & inrange(age0,-24,24) & rel_year>=0, gen(dummy)
		drop dummy1
	
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(24)
		regsave RD_Estimate using "Data_temp/election`var'_p1.dta", replace ci addlabel(outcome, `var', count, 1)
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(2)  h(24)
		regsave RD_Estimate using "Data_temp/election`var'_p2.dta", replace ci addlabel(outcome, `var',count, 2)
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy* contr*) p(1)  h(24)
		regsave RD_Estimate using "Data_temp/election`var'_p3.dta", replace ci addlabel(outcome, `var', count, 3)
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy* contr*) p(2)  h(24)
		regsave RD_Estimate using "Data_temp/election`var'_p4.dta", replace ci addlabel(outcome, `var', count, 4)
		
		* Bandwidth
	rdbwselect `var' age0 if age0!=0,  p(1)	
	global bw=e(h_mserd)	
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h($bw)
		regsave RD_Estimate using  "Data_temp/election`var'_p5.dta", replace ci addlabel(outcome, `var', count, 5)
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(48)
		regsave RD_Estimate using "Data_temp/election`var'_p6.dta", replace ci addlabel(outcome, `var', count, 6)
	rdrobust `var' age0 if age0!=0 & rel_year>=0, covs(dummy*) p(1)  h(12)
		regsave RD_Estimate using "Data_temp/election`var'_p7.dta", replace ci addlabel(outcome, `var', count, 7)
		}




clear
gen n=.
local m=1
foreach var in index  party_closer1 interest_polit vote_agree vote_party member_party {
	forvalues x = 1/7 {
			append using "Data_temp/election`var'_p`x'.dta"
			replace n=`m' if n==.
			}	
			local ++m
		}		


replace n=n-0.3 if count==1
replace n=n-0.2 if count==2
replace n=n-0.1 if count==3
replace n=n+0.1 if count==5
replace n=n+0.2 if count==6
replace n=n+0.3 if count==7
		
		

twoway (rcap ci_lo ci_up n, lcolor(gs8) lwidth(medthin)) ///
		(scatter coef n if count==1,  msize(medlarge) msymbol(D) mfcolor(white) mlwidth(medthick) mlcolor(black)) ///
		(scatter coef n if count==2, msize(medlarge) msymbol(O) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==3, msize(medlarge) msymbol(T) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==4, msymbol(S) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==5, msymbol(O) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)) ///
		(scatter coef n if count==6, msymbol(T) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)) ///
		(scatter coef n if count==7, msymbol(S) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)), ///
		yl(-.05(0.05)0.2) xsc(r(0.7 6.3))  xt("") ///
		xlabel(none) legend(order(2 "1 / - / 24" 3 "2 / - / 24" 4 "1 / Y / 24"  5 "2 / Y / 24" ///
		6 "1 / - / optimal" 7 "1 / - / 48" 8 "1 / - / 12") row(2) size(small) ///
		subtitle("Specification (polynomial order / controls / bandwidth in months)", size(medsmall)) ) ///
		subt("")  yt("RD estimate") ///
		 xlab(1 `""Index of" "political involvement""' 2 `""Supporting or close" "to one party""' ///
		 3 `""Interested in" "politics""' 4 `""Voting as a" "social norm""' 5 `""States a party" "to vote for""' 6 `""Member of a" "political party""', ///
		labsize(*0.9) ) graphregion(margin(zero)) ///
		yline(0, lwidth(thin) lcolor(gs12) lpattern(solid))

graph export "Figures/fg4_a.eps", replace
		
		
		
* t_1 - t_3 pooled
foreach var in  index  party_closer1 interest_polit vote_agree vote_party member_party { // 

	use "Data_temp/polit_involv.dta", clear
	
	foreach cov in female born_abroad mwork14 mum_lowedu white_brit  employed low_edu married ///
		 england  scotland wales north_ireland  {
			qui recode `cov' (.=99)
			qui tab `cov' if `var'<. & inrange(rel_age2,-24,24), gen(contr_`cov')
			drop contr_`cov'1
	}
	
		cap drop dummy*
		qui tab year if `var'<. & inrange(rel_age2,-24,24) & rel_year>=0, gen(dummy)
		drop dummy1
	
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(24)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p1.dta", replace ci addlabel(outcome, `var', count, 1)
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(2)  h(24)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p2.dta", replace ci addlabel(outcome, `var',count, 2)
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy* contr*) p(1)  h(24)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p3.dta", replace ci addlabel(outcome, `var', count, 3)
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy* contr*) p(2)  h(24)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p4.dta", replace ci addlabel(outcome, `var', count, 4)
		
		* Bandwidth
	rdbwselect `var' rel_age2 if rel_age2!=0,  p(1)	
	global bw=e(h_mserd)	
	rdrobust `var' rel_age2 if rel_age2!=0 & rel_year>=0, covs(dummy*) p(1)  h($bw)
		regsave RD_Estimate using  "Data_temp/electionpool`var'_p5.dta", replace ci addlabel(outcome, `var', count, 5)
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(48)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p6.dta", replace ci addlabel(outcome, `var', count, 6)
	rdrobust `var' rel_age2 if rel_age2!=0, covs(dummy*) p(1)  h(12)
		regsave RD_Estimate using "Data_temp/electionpool`var'_p7.dta", replace ci addlabel(outcome, `var', count, 7)
		}		
	

	
clear
gen n=.
local m=1
foreach var in index  party_closer1 interest_polit vote_agree vote_party member_party {
	forvalues x = 1/7 {
			append using "Data_temp/electionpool`var'_p`x'.dta"
			replace n=`m' if n==.
			}	
			local ++m
		}		


replace n=n-0.3 if count==1
replace n=n-0.2 if count==2
replace n=n-0.1 if count==3
replace n=n+0.1 if count==5
replace n=n+0.2 if count==6
replace n=n+0.3 if count==7	
		
		

twoway (rcap ci_lo ci_up n, lcolor(gs8) lwidth(medthin)) ///
		(scatter coef n if count==1,  msize(medlarge) msymbol(D) mfcolor(white) mlwidth(medthick) mlcolor(black)) ///
		(scatter coef n if count==2, msize(medlarge) msymbol(O) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==3, msize(medlarge) msymbol(T) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==4, msymbol(S) mfcolor(white) mlwidth(medthick) mlcolor(edkblue)) ///
		(scatter coef n if count==5, msymbol(O) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)) ///
		(scatter coef n if count==6, msymbol(T) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)) ///
		(scatter coef n if count==7, msymbol(S) mfcolor(gs12) mlwidth(medthick) mlcolor(dknavy)), ///
		yl(-.1(0.05)0.15) xsc(r(0.5 5.5))  xt("") ///
		xlabel(none) legend(order(2 "1 / - / 24" 3 "2 / - / 24" 4 "1 / Y / 24"  5 "2 / Y / 24" ///
		6 "1 / - / optimal" 7 "1 / - / 48" 8 "1 / - / 12") row(2) size(small) ///
		subtitle("Specification (polynomial order / controls / bandwidth in months)", size(medsmall)) ) ///
		subt("")   yt("RD estimate") ///
		 xlab(1 `""Index of" "political involvement""' 2 `""Supporting or close" "to one party""' ///
		 3 `""Interested in" "politics""' 4 `""Voting as a" "social norm""' 5 `""States a party" "to vote for""' 6 `""Member of a" "political party""', ///
		labsize(*0.9) )   graphregion(margin(zero)) ///
		yline(0, lwidth(thin) lcolor(gs12) lpattern(solid))
graph export "Figures/fg4_b.eps", replace
		

		